﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibHuman;
namespace Human
{
	/// <summary>
	/// Summary description for frmDSDeNghiKyHDLD.
	/// </summary>
	public class frmDSDeNghiKyHDLD : System.Windows.Forms.Form
	{
        private AccessData mDB = new AccessData();
        private DataSet ds = new DataSet();
        Language lan = new Language();
        string s_bophan = "", user_dn = "";
		private System.Windows.Forms.Button butThoat;
		private System.Windows.Forms.Button butIn;
        private System.Windows.Forms.Button butXem;
        private DateTimePicker dtp_denngay;
        private ComboBox cbo_bophan;
        private Label label1;
        private Label label2;
    	private System.ComponentModel.Container components = null;

		public frmDSDeNghiKyHDLD(string s_makp,string s_userdn)
		{
			InitializeComponent();
            lan.Read_Language_to_Xml(this.Name.ToString(), this);
            lan.Changelanguage_to_English(this.Name.ToString(), this);
            s_bophan = s_makp;
            user_dn = s_userdn;
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
        private void frmDSDeNghiKyHDLD_Load(object sender, System.EventArgs e)
        {
            load_bophan();
        }
        private void load_bophan()
        {
            cbo_bophan.DataSource = mDB.get_bophan().Tables[0];
            cbo_bophan.DisplayMember = "tenbp";
            cbo_bophan.ValueMember = "madv";
            cbo_bophan.SelectedIndex = -1;
        }
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmDSDeNghiKyHDLD));
            this.butThoat = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butXem = new System.Windows.Forms.Button();
            this.dtp_denngay = new System.Windows.Forms.DateTimePicker();
            this.cbo_bophan = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // butThoat
            // 
            this.butThoat.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThoat.Image = global::Human.Properties.Resources.close_r;
            this.butThoat.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThoat.Location = new System.Drawing.Point(188, 86);
            this.butThoat.Name = "butThoat";
            this.butThoat.Size = new System.Drawing.Size(65, 28);
            this.butThoat.TabIndex = 5;
            this.butThoat.Text = "&Thoát";
            this.butThoat.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThoat.UseVisualStyleBackColor = false;
            this.butThoat.Click += new System.EventHandler(this.butThoat_Click);
            // 
            // butIn
            // 
            this.butIn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butIn.Image = global::Human.Properties.Resources.print;
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(117, 86);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(65, 28);
            this.butIn.TabIndex = 4;
            this.butIn.Text = "In";
            this.butIn.UseVisualStyleBackColor = false;
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butXem
            // 
            this.butXem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butXem.Image = global::Human.Properties.Resources.ok1;
            this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXem.Location = new System.Drawing.Point(46, 86);
            this.butXem.Name = "butXem";
            this.butXem.Size = new System.Drawing.Size(65, 28);
            this.butXem.TabIndex = 3;
            this.butXem.Text = "  Xem";
            this.butXem.UseVisualStyleBackColor = false;
            this.butXem.Click += new System.EventHandler(this.butXem_Click);
            // 
            // dtp_denngay
            // 
            this.dtp_denngay.CustomFormat = "dd/MM/yyyy";
            this.dtp_denngay.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
            this.dtp_denngay.Location = new System.Drawing.Point(89, 12);
            this.dtp_denngay.Name = "dtp_denngay";
            this.dtp_denngay.Size = new System.Drawing.Size(121, 20);
            this.dtp_denngay.TabIndex = 1;
            this.dtp_denngay.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dtp_denngay_KeyDown);
            // 
            // cbo_bophan
            // 
            this.cbo_bophan.FormattingEnabled = true;
            this.cbo_bophan.Location = new System.Drawing.Point(89, 43);
            this.cbo_bophan.Name = "cbo_bophan";
            this.cbo_bophan.Size = new System.Drawing.Size(161, 21);
            this.cbo_bophan.TabIndex = 2;
            this.cbo_bophan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cbo_bophan_KeyDown);
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(12, 14);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(62, 15);
            this.label1.TabIndex = 10;
            this.label1.Text = "Đến ngày:";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.Location = new System.Drawing.Point(12, 43);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(44, 15);
            this.label2.TabIndex = 11;
            this.label2.Text = "Đơn vị:";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // frmDSDeNghiKyHDLD
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(263, 128);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.cbo_bophan);
            this.Controls.Add(this.dtp_denngay);
            this.Controls.Add(this.butThoat);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butXem);
            this.ForeColor = System.Drawing.Color.DarkBlue;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmDSDeNghiKyHDLD";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh sách đề nghị ký hợp đồng lao động";
            this.Load += new System.EventHandler(this.frmDSDeNghiKyHDLD_Load);
            this.ResumeLayout(false);

		}
		#endregion

		private void butThoat_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void txbHoTen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Enter)
			{
				SendKeys.Send("{Tab}");					
			}			
		}
	
		private void print(bool prn)
		{
            string m_user = "";
            m_user = mDB.user;
		    try
			{
				string sql=" SELECT l.manv,b.madv,b.tenbp as tenbophan,trim(l.ho)||' '||trim(l.ten) as Hoten,hd.hdldso as Hopdongso,to_char(hd.ngayhd,'dd/mm/yyyy') as Ngaykyhd,";
				sql += " to_char(l.ngaysinh,'dd/mm/yyyy') as Ngay_sinh,l.phai as gioitinh,trim(ct.tenctdt)||' - '||trim(bc.tenbang) as Nghenghiepcm,";
				sql += " trim(l.diachi)||', '||trim(h.tenquan)||', '||trim(t.tentt) as Thuong_tru,";
				sql += " mh.tenhd as Hop_dong,hd.thoigian as T_gian,to_char(hd.tungay,'dd/mm/yyyy') as Tu_ngay,";
				sql += " to_char(hd.denngay,'dd/mm/yyyy') as Den_ngay,mc.diengiai as Chuc_vu,hd.hs_lc,";
               	sql += " to_char(now,'dd') as ngay,to_char(now,'mm') as thang,to_char(now,'yyyy') as nam";
                sql += " ,b.sothutu as stt_bp,mc.stt as stt_cv";
                sql += " from " + m_user + ".llnv l inner join " + m_user + ".hopdong hd on hd.manv=l.manv";
                sql += " left join " + m_user + ".btdtt t on t.matt=l.t_diachi ";
                sql += " left join " + m_user + ".btdquan h on h.maqu=l.h_diachi";
                sql += " left join " + m_user + ".mahd mh on mh.mahd=hd.loaihd ";
                sql += " left join " + m_user + ".bophan b on b.madv=l.madv";
                sql += " left join " + m_user + ".ctdaotao ct on ct.mactdt=l.nnghiep";
                sql += " left join " + m_user + ".bangcap bc on l.td_nnghiep=bc.mabangcap";
                sql += " left join " + m_user + ".dmcv mc on mc.macv=hd.macv";
                sql += " inner join "+m_user+".max_lan ml on hd.manv=ml.manv";
                sql += " where ngaynghi is null  and (to_date(to_char(hd.denngay,'dd/mm/yyyy'),'dd/mm/yyyy')<=to_date('" + dtp_denngay.Text + "','dd/mm/yyyy'))";
                sql += " and hd.thoigian <> 0 and mh.nhombc <> 1 and hd.lan=ml.lan";
				if(cbo_bophan.SelectedIndex!=-1)
                    sql += " and l.madv= '"+cbo_bophan.SelectedValue.ToString().Trim()+ "'";
                sql += " order by b.sothutu,mc.stt,l.manv";
				ds=mDB.get_data(sql);
                ds.WriteXml("..\\xml\\h_dsdenghikyHDLD.xml", XmlWriteMode.WriteSchema);
				if (ds.Tables[0].Rows.Count>0)
				{

                    frmReport f = new frmReport(mDB, ds,lan.Change_language_MessageText( "DANH SÁCH ĐỀ NGHỊ KÝ HỢP ĐỒNG LAO ĐỘNG"), "h_dsdenghikyHDLD.rpt", true, user_dn);
						f.ShowDialog(this);
					
				}
				else
					MessageBox.Show(lan.Change_language_MessageText("Chưa có đầy đủ dữ liệu"),lan.Change_language_MessageText("Thông Báo"));
			}
			catch{}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			try
			{
				print(false);			
			}
			catch{}
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			print(true);
		}

        private void dtp_denngay_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}{F4}");
        }

        private void cbo_bophan_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                SendKeys.Send("{Tab}");
        }

		
	}
}
